home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- #
- #Very simple script illustrating how SD can be controlled from the command line
- #Don't hesitate to modify it, do tell us if you make some useful mods
- #
- #
- #
- #
-
- if [ "$1" = 'dl' ];
- then
- if [ "$#" -lt 2 ]; then
- echo "Missing url"
- else
- #add the item
- uid=`osascript -e 'tell application "Speed Download 2"' -e "AddURL \"$2\"" -e 'end tell'`
- #get it
- res=`osascript -e 'tell application "Speed Download 2"' -e "StartQueuedDownload $uid" -e 'end tell'`
- if [ "$res" -eq -1 ]; then
- echo "Too many downloads active, download queued with uid $uid"
- else
- echo "Download starting, uid for this download is $uid"
- fi
- fi
- elif [ "$1" = 'launch' ]; then
- echo `osascript -e 'tell application "Speed Download 2"' -e "activate" -e 'end tell'`
- elif [ "$1" = 'startq' ]; then
- osascript -e 'tell application "Speed Download 2"' -e "StartQueue" -e 'end tell' >/dev/null
- echo "Queue started"
- elif [ "$1" = 'stopq' ]; then
- osascript -e 'tell application "Speed Download 2"' -e "StopQueue" -e 'end tell' >/dev/null
- echo "Queue stopped"
-
- elif [ "$1" = 'info' ]; then
- if [ "$#" -lt 2 ]; then
- echo "missing uid"
- else
- echo `osascript -e 'tell application "Speed Download 2"' -e "GetDownloadInfo $2" -e 'end tell'`
- fi
- elif [ "$1" = 'add' ]; then
- if [ "$#" -lt 2 ]; then
- echo "missing url"
- else
- uid=`osascript -e 'tell application "Speed Download 2"' -e "AddURL \"$2\" startqueue false" -e 'end tell'`
- echo "Item added with uid: $uid"
- fi
- elif [ "$1" = 'start' ]; then
- if [ "$#" -lt 2 ]; then
- echo "missing uid"
- else
- res=`osascript -e 'tell application "Speed Download 2"' -e "StartQueuedDownload $2" -e 'end tell'`
- if [ $res -eq 0]; then
- echo "Download started"
- elif [ $res -eq -4]; then
- echo "bad uid"
- elif [ $res -eq -1]; then
- echo "too many active downloads"
- fi
- fi
- elif [ "$1" = 'stop' ]; then
- if [ "$#" -lt 2 ]; then
- echo "missing uid"
- else
- res=`osascript -e 'tell application "Speed Download 2"' -e "CancelDownload $2" -e 'end tell'`
- if [ $res -eq 0 ]; then
- echo "Download removed"
- else echo "Invalid uid"
- fi
- fi
- elif [ "$1" = 'remove' ]; then
- if [ "$#" -lt 2 ]; then
- echo "missing uid"
- else
- res=`osascript -e 'tell application "Speed Download 2"' -e "Remove $2" -e 'end tell'`
- if [ $res -eq 0 ]; then
- echo "0:element removed";
- elif [ $res -eq -1 ]; then
- echo "-1:element could not be removed because it is in use"
- else
- echo "-2:bad uid"
- fi
- fi
- elif [ "$1" = 'clear' ]; then
- res=`osascript -e 'tell application "Speed Download 2"' -e "Clearqueue" -e 'end tell'`
- if [ $res -eq 0 ]; then
- echo "Queue Cleared"
- else
- echo "Queue could not be cleared. elements may be in use"
- fi
-
- elif [ "$1" = 'url' ]; then
- if [ "$#" -lt 2 ]; then
- echo "missing uid"
- else
- res=`osascript -e 'tell application "Speed Download 2"' -e "GetDownloadURL $2" -e 'end tell'`
- if [ "$res" = "" ]; then
- echo "Invalid uid"
- else echo $res
- fi
- fi
- elif [ "$1" = 'quit' ]; then
- echo `osascript -e 'tell application "Speed Download 2"' -e "quit" -e 'end tell'`
- elif [ "$1" = 'list' ]; then
- osascript -e 'tell application "Speed Download 2"' -e "ListQueue" -e 'end tell'
- elif [ "$1" = 'listFolder' ]; then
- if [ "$#" -lt 2 ]; then
- echo "missing folder id"
- else
- osascript -e 'tell application "Speed Download 2"' -e "ListFolderContents $2" -e 'end tell'
- # if [ "$res" = "" ]; then
- # echo "Invalid folder id"
- # else echo $res
- # fi
- fi
- elif [ "$1" = 'listMain' ]; then
- osascript -e 'tell application "Speed Download 2"' -e "ListFolderContents 1" -e 'end tell'
- elif [ "$1" = 'folders' ]; then
- osascript -e 'tell application "Speed Download 2"' -e "ListFolders" -e 'end tell'
- elif [ "$1" = 'rfolders' ]; then
- if [ "$#" -lt 2 ]; then
- echo "missing host id"
- else
- osascript -e 'tell application "Speed Download 2"' -e "ListRemoteFolders $2" -e 'end tell'
-
- fi
- elif [ "$1" = 'listRfolder' ]; then
- if [ "$#" -lt 3 ]; then
- echo "missing host id,uid"
- else
- osascript -e 'tell application "Speed Download 2"' -e "ListRemoteFolderContents $3 host id $2" -e 'end tell'
-
-
- fi
- elif [ "$1" = 'listR' ]; then
- if [ "$#" -lt 2 ]; then
- echo "missing host id"
- else
- osascript -e 'tell application "Speed Download 2"' -e "ListRemoteQueue $2" -e 'end tell'
-
- fi
-
- elif [ "$1" = 'connect' ]; then
- if [ "$#" -lt 2 ]; then
- echo "missing server address"
- else
- res=`osascript -e 'tell application "Speed Download 2"' -e "ConnectHost \"$2\" user \"$3\" password \"$4\" " -e 'end tell'`
- if [ $res -eq 0 ]; then
- echo "Connection in progress"
- else echo "Connection attempt failed"
- fi
- fi
-
- elif [ "$1" = 'disconnect' ]; then
- if [ "$#" -lt 2 ]; then
- echo "missing host id"
- else
- res=`osascript -e 'tell application "Speed Download 2"' -e "DisconnectHost \"$2\"" -e 'end tell'`
- if [ $res -eq -1 ]; then
- echo "Invalid host ID"
- else echo "Disconnected"
- fi
- fi
- elif [ "$1" = 'refreshHost' ]; then
- if [ "$#" -lt 2 ]; then
- echo "missing host id"
- else
- res=`osascript -e 'tell application "Speed Download 2"' -e "RefreshHost $2" -e 'end tell'`
- if [ $res -eq -1 ]; then
- echo "Invalid host ID"
- else echo "refreshing..."
- fi
-
- fi
- elif [ "$1" = 'listH' ]; then
- res=`osascript -e 'tell application "Speed Download 2"' -e "ListHosts" -e 'end tell'`
- echo $res
- elif [ "$1" = 'connectS' ]; then
- if [ "$#" -lt 2 ]; then
- echo "missing server name"
- else
- res=`osascript -e 'tell application "Speed Download 2"' -e "ConnectFavourite \"$2\"" -e 'end tell'`
- if [ $res -eq -1 ]; then
- echo "Invalid server name"
- else echo "connection in progress"
- fi
- fi
- elif [ "$1" = 'listS' ]; then
- osascript -e 'tell application "Speed Download 2"' -e "ListFavourites" -e 'end tell'
-
- elif [ "$1" = 'saveS' ]; then
- if [ "$#" -lt 2 ]; then
- echo "missing host id"
- else
- res=`osascript -e 'tell application "Speed Download 2"' -e "AddHostToFavourites $2" -e 'end tell'`
- if [ $res -eq -1 ]; then
- echo "Invalid host ID"
- else echo "added"
- fi
- fi
- elif [ "$1" = 'removeS' ]; then
- if [ "$#" -lt 2 ]; then
- echo "missing server name"
- else
- res=`osascript -e 'tell application "Speed Download 2"' -e "RemoveFavourite \"$2\"" -e 'end tell'`
- if [ $res -eq -1 ]; then
- echo "Invalid server name"
- else echo "removed"
- fi
- fi
-
- elif [ "$1" = 'addRemote' ]; then
-
- if [ "$#" -lt 3 ]; then
- echo "missing hostID, uid"
- else
- res=`osascript -e 'tell application "Speed Download 2"' -e "AddRemoteItemToQueue $3 host id $2" -e 'end tell'`
- if [ "$res" = "0" ]; then
- echo "Invalid hostID/uid"
- else echo "Item added with uid $res"
- fi
- fi
- elif [ "$1" = 'ddl' ]; then
-
- if [ "$#" -lt 3 ]; then
- echo "missing hostID, uid"
- else
- res=`osascript -e 'tell application "Speed Download 2"' -e "AddDirectTransfer $2 UID $3" -e 'end tell'`
- if [ "$res" = "0" ]; then
- echo "Invalid hostID/uid"
- else echo "Item added with uid $res"
- fi
- fi
-
- elif [ "$1" = 'bwstats' ]; then
- osascript -e 'tell application "Speed Download 2"' -e "BWstats" -e 'end tell'
- else
- echo "usage:"
- echo "sdcli launch opens Speed Download 2"
- echo "sdcli dl <url> downloads the specified url, returns a uid"
- echo "sdcli add <url> Adds the specified url to the queue, without downloading it, returns a uid"
- echo "sdcli stop <uid> cancels the download corresponding to the uid"
- echo "sdcli start <uid> starts the download corresponding to the uid"
- echo "sdcli remove <uid> removes the download corresponding to the uid"
- echo "sdcli clear removes all downloads"
- echo "sdcli info <uid> returns a status string for the specified uid"
- echo "sdcli url <uid> returns the url for the specified uid"
- echo "sdcli list lists all uids and and urls on the local machine"
- echo "sdcli startq starts the queue"
- echo "sdcli stopq stops the queue"
- echo "sdcli quit quit Speed Download 2"
- echo "sdcli listFolder <uid> lists the contents of the local folder with the specified uid"
- echo "sdcli listMain lists the contents of my downloads"
- echo "sdcli folders lists the local folders"
- echo "sdcli listRFolder <hostID> <uid> lists the contents of the folder with uid <uid> on the host specified"
- echo "sdcli listR <hostID> lists all the urls on the specified remote host"
- echo "sdcli rfolders <hostID> lists the folders on the specified host"
- echo "sdcli connect <address> initiates a connection to the specified address"
- echo "sdcli disconnect <hostID> disconnects the specified connection"
- echo "sdcli listH lists active connections"
- echo "sdcli connectS <name> connects the named server from my servers"
- echo "sdcli listS lists the servers in my servers, and their status"
- echo "sdcli saveS <hostID> saves the specified connection in my servers"
- echo "sdcli removeS <name> removes the named entry from my servers"
- echo "sdcli addRemote <hostID> <uid> adds the specified download from a remote host to the local host"
- echo "sdcli refreshHost <hostID> refreshes the specified host"
- echo "sdcli bwstats Displays bandwidth usage"
- echo "sdcli ddl <hostID> <uid> adds the specified download from a remote host to the local host as a direct transfer"
- fi
-